<?php

namespace App\Repositories;
use Image;

class ProjectsRepository{
    public function create($request){
        // 通过projects()关系，储存数据，不用再单独存user_id字段，已经自动存储了
        $request->user()->projects()->create([
            'name'=> $request->name,
            'thumbnail'=> $this->thumb($request)

        ]);
    }

    public function thumb($request){
        if($request->hasFile('thumbnail')){
            // 存储原始图片
            $thumb = $request->thumbnail;
            $name = $thumb->hashName();
            $thumb->storeAs('public/thumbs/original', $name);
            return $name;
        }

    }

}